package com.sand.controller;


import com.sand.dto.supplier.PurchaseAdd;
import com.sand.dto.supplier.PurchaseAll;
import com.sand.dto.supplier.SelectePurchase;
import com.sand.entity.sell.Purchase;
import com.sand.result.ResponseResult;
import com.sand.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/purchase")
public class PurchaseController {

    @Autowired
    private PurchaseService purchaseService;

    /**
     * 发起采购
     */
    @PostMapping("/add")
    public ResponseResult<Integer> add(@RequestBody PurchaseAdd purchaseAdd){
        Integer i = purchaseService.add(purchaseAdd);
        return new ResponseResult<Integer>().ok(i);
    }

    /**
     * 条件查询采购单
     */
    @PostMapping("/get")
    public ResponseResult<List<Purchase>> get(@RequestBody SelectePurchase selectePurchase){
        List<Purchase> list = purchaseService.get(selectePurchase);
        return new ResponseResult<List<Purchase>>().ok(list);
    }

    /**
     * id查询采购单
     */
    @PostMapping("/gid")
    public ResponseResult<Purchase> gid(@RequestBody Integer purchaseid){
        Purchase purchase = purchaseService.getById(purchaseid);
        return new ResponseResult<Purchase>().ok(purchase);
    }

    /**
     * 查看采购详细
     */
    @PostMapping("/all")
    public ResponseResult<PurchaseAll> all(@RequestBody Integer purchaseid){
        PurchaseAll purchaseAll =  purchaseService.all(purchaseid);
        return new ResponseResult<PurchaseAll>().ok(purchaseAll);
    }


    /**
     * 完成采购
     */
    @PostMapping("/ok")
    private ResponseResult<Integer> ok(@RequestBody Integer purchaseid){
        Integer i = purchaseService.ok(purchaseid);
        return new ResponseResult<Integer>().ok(i);
    }

}
